package com.example.gustavo.hello.utils;


import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class StreamUtil {
	/**
	 * 将inputstream转化成String
	 * @param is inputstream 输入流
	 * @return string 字符串
	 */
	public static String readInputStream(InputStream is) throws IOException {
		
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			byte[] bs = new byte[1024];
			int len = 0;
			while ((len = is.read(bs)) != -1) {
				baos.write(bs, 0, len);
			}
			is.close();
			baos.close();
			byte[] temp = baos.toByteArray();
			return new String(temp);


			/*StringBuilder sb = new StringBuilder();
			byte[] bs = new byte[1024];
			int len = 0;
			while((len=is.read(bs))!=-1){
				sb.append(new String(bs, 0, len));
			}
			is.close();
			return sb.toString();*/

		

	}

}
